﻿//-----------------------------------------------------------------------
// <copyright>
// This file is subject to the terms and conditions of the Microsoft Public License (MS-PL).
// See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL for more details.
// </copyright>
//----------------------------------------------------------------------- 
using System.Linq;
using Fulcrum.WeakEventManager;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Fulcrum.UnitTests.WeakEventManager
{
    [TestClass]
    public class WeakEventManagerGenerationUnitTests
    {
        public WeakEventManagerGenerationUnitTests()
        {
            // nothing
        }

        WeakEventManagerGenerationUnitTestDouble generationUnit;

        [TestInitialize()]
        public void MyTestInitialize()
        {
            var config = MockWemGeneratorConfig.CreateMock();
            this.generationUnit = new WeakEventManagerGenerationUnitTestDouble(config);
        }
        
        [TestMethod]
        public void TestWeakEventManagerGenerationUnitName()
        {
            Assert.AreEqual("WeakEventManager", this.generationUnit.Name);
        }

        [TestMethod]
        public void TestWeakEventManagerGenerationUnitSettings()
        {
            Assert.IsNotNull(this.generationUnit.Settings);
            Assert.IsInstanceOfType(this.generationUnit.Settings, typeof(WeakEventManagerSettings));
        }

        [TestMethod]
        public void TestWeakEventManagerGenerationUnitDataContextCount()
        {
            this.generationUnit.CreateDataContexts();
            Assert.AreEqual(2, this.generationUnit.DataContexts.Count);
        }

        [TestMethod]
        public void TestWeakEventManagerGenerationUnitCreateDataContextTwice()
        {
            this.generationUnit.CreateDataContexts();
            this.generationUnit.CreateDataContexts();
            Assert.AreEqual(2, this.generationUnit.DataContexts.Count);
        }

        [TestMethod]
        public void TestWeakEventManagerGenerationUnitDataContextOne()
        {
            this.generationUnit.CreateDataContexts();

            var dataContext = (WeakEventManagerGenerationDataContext) this.generationUnit.DataContexts.ElementAt(0);

            Assert.AreEqual("Mock Company", dataContext.Company);
            Assert.AreEqual("Mock Copyright", dataContext.Copyright);
            Assert.AreEqual("MockEventArgsOne", dataContext.EventArgsType);
            Assert.AreEqual("MockEventNameOne", dataContext.EventName);
            Assert.AreEqual("MockEventSourceOne", dataContext.EventSourceType);
            Assert.AreEqual("MockNameOne", dataContext.ManagerName);
            Assert.AreEqual("MockNameOne", dataContext.Name);
            Assert.AreEqual("Mock.Namespace", dataContext.Namespace);
            Assert.AreEqual("MockNameOne.Generated", dataContext.OutputFileName);
            Assert.AreEqual("", dataContext.OutputPath);
            Assert.AreEqual("WeakEventManager.t4", dataContext.TemplateFileName);
        }
    }
}
